package com.fbli.test.controller;

import com.fbli.test.common.entity.projectIter.IterModelReqMsg;
import com.fbli.test.common.entity.projectIter.ProjectIterAddMsg;
import com.fbli.test.common.entity.projectIter.ProjectIterMsg;
import com.fbli.test.common.result.ResultParam;
import com.fbli.test.common.result.ResultSend;
import com.fbli.test.entity.ProjectIter;
import com.fbli.test.service.ProjectIterService;
import com.fbli.test.service.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "项目迭代功能")
@RestController
@RequestMapping("/projectIter")
public class ProjectIterController {
    @Autowired
    ProjectIterService projectIterService;
    @Autowired
    ProjectService projectService;

    @ApiOperation("新增迭代")
    @PostMapping("/add")
    public ResultParam add(@RequestBody ProjectIterAddMsg addMsg){
        boolean b = projectIterService.add(addMsg);
        if (b){
            return ResultSend.success("添加成功！");
        }else {
            return ResultSend.fail("添加失败！");
        }
    }
    @ApiOperation("更新迭代")
    @PostMapping("/update")
    public ResultParam update(@RequestBody ProjectIterMsg projectIterMsg){
        if (projectIterMsg.getIterId()>0){
            boolean b = projectIterService.update(projectIterMsg);
            if (b){
                return ResultSend.success("更新成功！");
            }else {
                return ResultSend.fail("更新失败！");
            }
        }else {
            return ResultSend.fail("id不存在！");
        }
    }
    @ApiOperation("获取项目迭代数据")
    @PostMapping("/getIterModel")
    public ResultParam getIterModel(@RequestBody IterModelReqMsg msg) {
        ProjectIter projectIter = projectIterService.selectById(msg.getIterId());
        if (projectIter == null) ResultSend.fail("没有id=" + msg.getIterId() + "的项目迭代数据");
        return ResultSend.success(projectIter);
    }
}
